using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.DirectoryServices;
using System.Drawing;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Mail;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Dimok.Data;
using Dimok.Data.Database;
using Dimok.Exceptions;
using Dimok.Aspx.Manager.Lib;
using Data;

namespace Dimok.Aspx.Manager.Underwriting
{
	/// <summary>
	/// Summary description for CallBack.
	/// </summary>
	public partial class CallBack : Page_AL{
		protected HtmlTableCell elBuyer;
		//protected HtmlGenericControl spnUnderwriter;
		protected void Page_Load(object sender, System.EventArgs e){
			try{
				if( UOX.QueryParam.IsFax )
					body.Attributes.Add("onload","faxMe()");
				string displayName = uox.DisplayName;
				//spnUnderwriter.InnerHtml = displayName != "SQL Server" ? displayName : "Alex Amis";
				Response.Cache.SetCacheability(HttpCacheability.NoCache);

				if( UserObjectEx.QueryParam.IsFax )//throw new ApplicationException("It's a Fax! Allright!");
					SQLHelperEx.ExecuteNonQueryEx(uox.db,"sh_ArchiveRow",uox.applID,"v_FaxToDealer");

				DataSet dsCallBack = uox.CallBack(Request["HistID"]);
				ltrCallBack.Text = SQL.XmlInnerText(dsCallBack);

				DataRow drCasllBack = dsCallBack.Tables[0].Rows[0];
				if( (bool)drCasllBack["Declined"] )divLoanInfo.Visible = false;

				if( drCasllBack["LastName1"] == DBNull.Value )trCoBuyer.Visible = false;

				string callBackUser = dsCallBack.Tables[0].Rows[0]["UserName"].ToString();
				DirectoryEntry[] deBuyers = uox.CallBackBuyers;
				DataTable dtBuyers = new DataTable();
				dtBuyers.Columns.Add("Name");
				dtBuyers.Columns.Add("Ext");
				dtBuyers.Columns.Add("Sort");
				dtBuyers.Columns.Add("TextStyle",typeof(string),"IIF(Sort='0','underline','none')");
				foreach( DirectoryEntry de in deBuyers )
					dtBuyers.Rows.Add(new object[]{ADs.Props.DisplayName(de).Replace("Jona"," Jona"),"Ext:"+ADs.TelephoneExtention(de),ADs.Props.SAMAccountName(de) == callBackUser ? "0" : "1"});

				DataView dvBuyers = dtBuyers.DefaultView;
				dvBuyers.Sort = "Sort,Name";
				tblBuyers.DataSource = dvBuyers;
				tblBuyers.DataBind();

				repConditions.DataSource = uox.CallBackConditions;
				repConditions.DataBind();

				imgLogo.Src = "http://"+Request["SERVER_NAME"]+":"+Request["SERVER_PORT"]+imgLogo.Src;

			}catch(Exception exc){
				throw new ASPException(exc,"IsFax",UserObjectEx.QueryParam.IsFax+"");
				//ClientException.Publish(exc,true);
				//uox.FaxCallBack(Dimok.Config.application.FaxErrorEMail,ClientException.GetMessages(exc));
			}
		}
		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    

		}
		#endregion
	}
}
